// 认证相关API

import api from '../index';
import {
  ApiResponse,
  SendVerificationCodeRequest,
  RegisterRequest,
  RegisterAdminRequest,
  LoginRequest,
  LoginResponse,
  ResetPasswordRequest,
  ChangePasswordRequest,
  ReviewAdminApplicationRequest,
  User,
} from '../../types';

// 发送验证码
export const sendVerificationCode = async (
  data: SendVerificationCodeRequest
): Promise<ApiResponse<null>> => {
  const response = await api.post('/auth/send-verification-code', data);
  return response.data;
};

// 用户注册
export const register = async (
  data: RegisterRequest
): Promise<ApiResponse<User>> => {
  const response = await api.post('/auth/register', data);
  return response.data;
};

// 管理员注册
export const registerAdmin = async (
  data: RegisterAdminRequest
): Promise<ApiResponse<User>> => {
  const response = await api.post('/auth/register-admin', data);
  return response.data;
};

// 用户登录
export const login = async (
  data: LoginRequest
): Promise<ApiResponse<LoginResponse>> => {
  const response = await api.post('/auth/login', data);
  return response.data;
};

// 刷新Token
export const refreshToken = async (): Promise<ApiResponse<LoginResponse>> => {
  const response = await api.post('/auth/refresh-token');
  return response.data;
};

// 重置密码
export const resetPassword = async (
  data: ResetPasswordRequest
): Promise<ApiResponse<null>> => {
  const response = await api.post('/auth/reset-password', data);
  return response.data;
};

// 修改密码
export const changePassword = async (
  data: ChangePasswordRequest
): Promise<ApiResponse<null>> => {
  const response = await api.post('/auth/change-password', data);
  return response.data;
};

// 审核管理员申请
export const reviewAdminApplication = async (
  userId: number,
  data: ReviewAdminApplicationRequest
): Promise<ApiResponse<null>> => {
  const response = await api.post(`/auth/admin/applications/${userId}/review`, data);
  return response.data;
}; 